var User = function(){


	var thiz=this;
	var QueryRole = new Ext.data.JsonStore(
			{url : '../UserManagement/QueryRole.form?timesnap=' + new Date().getTime(),
				root : 'result',
				fields : ['DEPARTMENT_ID', 'ROLE_NAME','ID'],
	
				listeners : {
					scope : this,
					beforeload : function(thiz) {
						thiz.baseParams = {
							start : 0,
							limit : 9999
						};
					}
				}
	});
	
	
	var addRoleComboBox = new Ext.form.ComboBox( {
		fieldLabel : '角色',
		//hiddenName : 'type',
		store: QueryRole,
		mode : 'local',
		displayField : 'ROLE_NAME',
		triggerAction : 'all',
		editable : false,
		valueField : 'ID',
		typeAhead : true,
		width : 200,
		selectOnFocus : true,
		selectOnChange : true
	});

	var editRoleComboBox = new Ext.form.ComboBox( {
		fieldLabel : '角色',
		//hiddenName : 'type',
		store: QueryRole,
		mode : 'local',
		displayField : 'ROLE_NAME',
		triggerAction : 'all',
		editable : false,
		valueField : 'ID',
		typeAhead : true,
		width : 200,
		selectOnFocus : true,
		selectOnChange : true
	});
	var tempvar = new Ext.form.TextField({
		fieldLabel: 'Temp',
		width : 200,
		name:'temp',
		allowBlank: false
	});


	var addUserName = new Ext.form.TextField({
		fieldLabel: '用户名称',
		width : 200,
		name:'addUserName',
		allowBlank: false
	});
	var addUserNum = new Ext.form.TextField({
		fieldLabel: '用户编号',
		width : 200,
		name:'addUserNum',
		allowBlank: false
	});
	
	var pass="";
	var PassWord = new Ext.form.Checkbox({
		boxLabel: '默认密码 123456',
		scope : this,
	    listeners : {
			scope : this,
			check : function(thiz,checked){
			
			}
		}
	});
	
	
	
	var Email = new Ext.form.TextField({
		fieldLabel: 'E-mail',
		width : 200,
		name:'email',
		allowBlank: true
	});
	
	//查找
	var SearchName = new Ext.form.TextField({
	
		fieldLabel: '用户名称',
		width : 200,
		name:'userSearchName',
		allowBlank: true
	});
	
	var SearchNum = new Ext.form.TextField({
		fieldLabel: '用户编号',
		width : 200,
		name:'usernum',
		allowBlank: true
	});
	var SearchTel = new Ext.form.TextField({
		fieldLabel: '电话',
		width : 200,
		name:'tel',
		allowBlank: true
	});
	var SearchEmail = new Ext.form.TextField({
		fieldLabel: 'E-mail',
		width : 200,
		name:'email',
		allowBlank: true
	});
	
	//修改
	var EditName = new Ext.form.TextField({
		fieldLabel: '用户名称',
		width : 200,
		name:'username',
		allowBlank: false
	});
	var EditNum = new Ext.form.TextField({
		fieldLabel: '用户编号',
		width : 200,
		name:'usernum',
		allowBlank: false
	});
	
	var EditId = new Ext.form.TextField({
		fieldLabel: 'Id',
		width : 200,
		name:'userid',
		allowBlank: false
	});
	
	//删除
	
	
	
	var addUserDetail = new Ext.form.FormPanel({
		el:'form',
		labelAlign:'left',
		labwidth:50,
		frame:true,
		items : [{layout:'column',defaults:{layout:'form'},
			      items:[{columnWidth:3,items:[addUserNum]},
			      		 {columnWidth:3,items:[addUserName]},
			      		 {columnWidth:3,items:[addRoleComboBox]},
			      		 {columnWidth:3,items:[PassWord]}
			      		 ]
			      }]
	});
	
	createUserStore= new Ext.data.JsonStore({
		url : '../UserManagement/addUser.form?timesnap=' + new Date().getTime(),
		
				listeners : {
					scope : this,
					beforeload : function(thiz) {
						thiz.baseParams = {
						userName:addUserName.getValue(),
						userId : addUserNum.getValue(),
						RoleId : addRoleComboBox.getValue(),
						passWord:"123456"
						};
					}
				}
			});
	
	
	
	
	var addUser = new Ext.Window({
		el:'addUser',
		layout:'fit',
		title: '添加用户',
        width: 400,
        height:300,
         closeAction: 'hide',
        items:[addUserDetail],
         buttons:[{text:'确认',icon: '../resources/icons/accept.png',scope:this,handler:function(){
         	if (PassWord.checked && addUserName.getValue!=null && addUserNum.getValue!=null){
         		var pass="123456";
         		
         		createUserStore.load();
         		Utils.info("保存成功","系统提示");	
         	}else{
         		alert("默认密码、用户名、用户编号不能为空");
         		return ;
         	}
         	}},
         {text:'清空',icon: '../resources/icons/arrow_undo.png',scope:this,handler:function(){
         	}}
         ]
});


	var search = new Ext.form.FormPanel({
		el:'search',
		labelAlign:'left',
		labwidth:50,
		frame:true,
		items : [{layout:'column',defaults:{layout:'form'},
			      items:[
			      		 {columnWidth:3,items:[SearchName]},
			      		  {columnWidth:3,items:[SearchNum]},
			      		   {columnWidth:3,items:[SearchTel]},
			      		    {columnWidth:3,items:[SearchEmail]}
			      		 ]
			      		 }]
			      		 
	});
	

	function Search(){

	}
	
	var delInfoStore = new Ext.data.JsonStore(
			{url : '../UserManagement/DelUser.form?timesnap=' + new Date().getTime(),
				root : 'userInfo',
				fields : ['userId', 'id', 'userName',
						'userDesc', 'userAdmin', 'roleId',
						'branchId', 'createUser', 'createDate', 
						'isActive','beginFlag', 'endFlag', 'departmentId', 'email',
						'phone', 'gender', 'age'],			
						
						
						
				listeners : {
					scope : this,
					beforeload : function(thiz) {
						thiz.baseParams = {
						userName:tempvar.getValue()
						};
					}
				}
			});
	
	
	var saveTract = function(bs){

	}
	
	var createInfoStore = new Ext.data.JsonStore(
			{url : '../UserManagement/QueryUser.form?timesnap=' + new Date().getTime(),
				root : 'result',
				fields : ['username', 'user_id','id','role_id','DEPARTMENT_ID'],
	
				listeners : {
					scope : this,
					beforeload : function(thiz) {
						thiz.baseParams = {
							userName:SearchName.getValue(),
							id:SearchNum.getValue(),
							phone:SearchTel.getValue(),
							email:SearchEmail.getValue()
						};
					}
				}
	});
	
	var searchUser = new Ext.Window({
		el:'searchUser',
		layout:'fit',
		title: '查询用户',
        width: 400,
        height:300,
         closeAction: 'hide',
        items:[search],
         buttons:[{text:'确认',icon: '../resources/icons/accept.png',scope:this,
         		   handler:function(){
         		   createInfoStore.load();
         	}
         	
         	},
         
         {text:'清空',icon: '../resources/icons/arrow_undo.png',scope:this,handler:function(){
         	}}
         ]
	});

	var edit = new Ext.form.FormPanel({
		el:'edit',
		labelAlign:'left',
		labwidth:50,
		frame:true,
		items : [{layout:'column',defaults:{layout:'form'},
			      items:[{columnWidth:3,items:[EditId]},
			      		 {columnWidth:3,items:[EditName]},
			      		 {columnWidth:3,items:[editRoleComboBox]},
			      		 {columnWidth:3,items:[EditNum]}
			      		 ]
			      		 }]
	});
	var xg = Ext.grid;
	var sm = new Ext.grid.CheckboxSelectionModel();
	var createGrid = new Ext.grid.GridPanel({
	sm: sm,
		width : 930,
		height : 300,
		store : createInfoStore,
		scope : this,
		listeners : {
			scope : this,
			rowmousedown : function(grid,index,e){
				var data = grid.store.getAt(index).data;
			}
		},
		columns : [
		sm,
			{header:'id',sortable: true,width: 150,dataIndex:'id'},
			{header:'用户编号',sortable: true,width: 150,dataIndex:'user_id'},
		    {header:'用户名',sortable: true,width: 100, dataIndex:'username'}],
		           
       bbar:new Ext.PagingToolbar({
		 pageSize: 10,
         store: createInfoStore,
         displayInfo: true,
         displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
         emptyMsg: "没有记录..."
       })
	});
	
	var agree = new Ext.form.Radio( {
		boxLabel : '是',
		name : 'status',
		checked:true,
		inputValue : 11
	});

	var unAgree = new Ext.form.Radio( {
		boxLabel : '否',
		name : 'status',
		inputValue : 12
	});
	
	var isAgree = new Ext.form.RadioGroup({
		fieldLabel : '是否签约',
		columns : 2,
		items : [agree,unAgree]
	});
	
	var remark = new Ext.form.TextArea({
		fieldLabel : '合同细节',
		width : 840,
		height:200
	});

	var updateUser = new Ext.data.Connection({
		waitTitle : '系统提示',
		waitMsg : '数据提交中，请稍候...',
		url:'../UserManagement/updateUser.form?timesnap=' + new Date().getTime(),
		method:'post'
	});

	var editUser = new Ext.Window({
		el:'editUser',
		layout:'fit',
		title: '修改用户',
        width: 400,
        height:300,
         closeAction: 'hide',
        items:[edit],
         buttons:[{text:'确认',icon: '../resources/icons/accept.png',scope:this,
         		handler:function(){ 
         			Utils.confirm2({
					msg:"是否更改数据信息？",
					width:220,
						fn:function(){
							Utils.request(updateUser,{
							params:{
								userName: EditName.getValue(),
								userId: EditNum.getValue(),
								id: EditId.getValue(),
								DepartID :tempvar.getValue(),
								RoleId : editRoleComboBox.getValue()
							},
							success:function(data){
								Utils.info("保存成功","系统提示");	
							}
						  })			
						}
					})
         		}
         	},
         
         {text:'清空',icon: '../resources/icons/arrow_undo.png',scope:this,handler:function(){
         	}}
         ]
	});
	
	
	
	
	this.createPanel = new Ext.form.FormPanel({
		frame : true,
		width : 800,
		fileUpload: true, 
		labelWidth : 85,
		buttons : [
		           {text:'新增',icon: '../resources/icons/add.png',scope:this,handler:function()
		           		{addUser.show();	}
		           	},
		           {text:'查询',icon: '../resources/icons/find.png',scope:this,handler:function()
		           		{searchUser.show();	}
		           	},
		           	{text:'修改',icon: '../resources/icons/application_edit.png',scope:this,
		           		handler:function(){
		           			var count=createGrid.getSelectionModel().getSelections();
		           			if(count.length==0){
		           				Utils.warn2('请选择一条记录！',180);
								return ;
		           			}else if(count.length>1){
								Utils.warn2('只能选择一条记录！',180);
								return;}
								EditName.setValue(count[0].data.username);
								EditNum.setValue(count[0].data.user_id);
								EditId.setValue(count[0].data.id);
								editRoleComboBox.setValue(count[0].data.role_id);
								tempvar.setValue(count[0].data.DEPARTMENT_ID);
								//alert(tempvar.getValue());
								
								editUser.show();
					
						}		           		
		           	}
		           ],
		items : [{layout:'column',defaults:{layout:'form'},
			      items:[]
				},createGrid],
	   listeners: {
	    	render: {fn:function(){ 
				createInfoStore.load();
				QueryRole.load();
			}}
		}
	});
	//确立查询人员
		var  conn = new Ext.data.Connection({
        method: 'POST',
        url: '../UserManagement/QueryUser.form?timesnap=' + Date.parse(new Date())
    });
	
	
	
	
	
	
	
	//确定立项信息路径
	var addCon = new Ext.data.Connection({
		url:'../project/doCreateProject.form?timesnap=' + new Date().getTime(),
		method:'post'
	});
	
	
	
	var doCreate = function(dp){
			if(projectId!=''){
		    var r = isAgree.getValue();  
		    var value = r.inputValue;  
			Utils.request(addCon,{
				params:{
					project_id:projectId,
					project_status:value,
					remark:remark.getValue()
				},
				success:function(data){
					if(data.result=='true'){
						Utils.info("操作成功","系统提示");	
						createInfoStore.reload();
						dp.getForm().reset();
					}else{
						Utils.info("操作失败","系统提示");	
					}
				}
			});
		}else{
			Utils.info("请选择确定要立项的项目","系统提示");	
		}
	};
};